class Item:
    total_items = 0  # 初始化类属性

    def __init__(self, title, author):
        self.title = title
        self.author = author
        Item.total_items += 1  # 更新类属性

    def __str__(self):
        return f"《{self.title}》 by {self.author}"


class Book(Item):  # 继承基类
    def __init__(self, title, author, pages):
        super().__init__(title, author)
        self.pages = pages

    def __str__(self):
        return f"《{self.title}》 by {self.author}，共{self.pages}页"


class DVD(Item):  # 继承基类
    def __init__(self, title, author, duration):
        super().__init__(title, author)
        self.duration = duration

    def __str__(self):
        return f"《{self.title}》 by {self.author}，时长{self.duration}分钟"


# 测试代码
book1 = Book("Python编程", "John", 300)
dvd1 = DVD("电影艺术", "Alice", 120)
print(book1)  # 应输出：《Python编程》 by John，共300页
print(dvd1)  # 应输出：《电影艺术》 by Alice，时长120分钟
print(Item.total_items)  # 应输出：2
